<?php
/*
 * Created on Apr 30, 2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

require_once("model/Player.php");

class SecurityDAO{
	var $conn;
	
	public function __construct($conn){
		$this->conn =& $conn;
	}
	
	public function login($emailAddr,$pw){
		$password = md5($pw);
		$me = null;
		
		if($stmt = $this->conn->prepare("CALL PLAYER_LOGIN(?,?)")){
			$stmt->bind_param("ss",$emailAddr,$password);
			$stmt->execute();
			$stmt->bind_result($_playerid,$_firstname,$_mi,$_lastname,$_emailaddress,$_hometown,$_currentcity,$_bio,$_dob,$_verified,$_locked,$_admin,$_deleted);
			$me = new Player();
			while($stmt->fetch()){
				$me->playerid = $_playerid;
				$me->playerid = $_playerid;
				$me->firstName = $_firstname;
				$me->MI = $_mi;
				$me->lastName = $_lastname;
				$me->emailAddress = $_emailaddress;
				$me->homeTown = $_hometown;
				$me->currentCity = $_currentcity;
				$me->bio = $_bio;
				$me->dob = $_dob;
				$me->verified = $_verified;
				$me->locked = $_locked;
				$me->admin = $_admin;
				$me->deleted = $_deleted;
			}
			$stmt->close();
		}
		else{
			printf("Error occurred in preparing statment for SessionMgmt::login.<br/>Details: %s",$stmt->error);
		}
		$this->conn->close();
		
		return $me;	
	}
	
	public function __destruct(){
		
	}
}
?>
